#coding:utf-8
from django import forms
import json,re
class TaskForm(forms.Form):
    data = forms.CharField()
    def clean_data(self):
        mail_rule= re.compile(r"\w+(?:\.\w+)?@\w+\.\w+")
        http_rule = re.compile(r"(?:http://)?([^/]+)")
        data = self.cleaned_data['data']
        task = json.loads(data)
        if not mail_rule.match(task['address']):
            raise forms.ValidationError(u"邮件格式不正确")
        index =0
        for item in task['urls']:
            match = http_rule.match(item['url'])
            if match:
                task['urls'][index] = match.group(1)
                index+=1
            else:
                 raise forms.ValidationError("url format error!")
        return task

class Task1Form(forms.Form):
    task_name = forms.CharField()
    store_name = forms.CharField()
    store_url = forms.CharField()
    stat = forms.IntegerField()
